package com.qiang.test01;

import com.qiang.test01.domain.Student;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Demo01 {
    public static void main(String[] args) throws IOException {
//        要求按照成绩总分从高到低写入文本文件，最后在从文件中把读取数据显示在控制台
//
//        格式：姓名,语文成绩,数学成绩,英语成绩 举例：林青霞,98,99,100
//
//        控制台执行结果图：
        Scanner sc = new Scanner(System.in);
        ArrayList<Student> list = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入第" + (i + 1) + "个学生姓名");
            String name = sc.next();
            System.out.println("请输入语文成绩");
            int chinese = sc.nextInt();
            System.out.println("请输入数学成绩");
            int math = sc.nextInt();
            System.out.println("请输入英语成绩");
            int english = sc.nextInt();
            Student st = new Student(name, chinese, math, english);
            list.add(st);
        }

        //创建输出流
        BufferedWriter bw = new BufferedWriter(new FileWriter("kaoshi1126\\student.txt", true));

        //StringBuilder sb = new StringBuilder();
        for (int i = list.size() - 1; i >= 0; i--) {
            //System.out.println(list.get(i));
            /*sb.append(list.get(i).getName() + ",");
            sb.append(list.get(i).getChinese() + ",");
            sb.append(list.get(i).getMath() + ",");
            sb.append(list.get(i).getEnglish());*/
            String name = list.get(i).getName();
            int chinese = list.get(i).getChinese();
            int math = list.get(i).getMath();
            int english = list.get(i).getEnglish();
            //String s = sb.toString();
            bw.write(name + "," + chinese + "," + math + ',' + english);
            bw.newLine();
        }
        bw.close();


    }
}
